using System.Reflection;
using System.Utility.System.Utility.Resources;

namespace System.Utility.Data.Validation
{
	public class LengthValidator : Validator
	{
		private int _MinLength;

		private int _MaxLength;

		public int MaxLength
		{
			get
			{
				return _MaxLength;
			}
		}

		public int MinLength
		{
			get
			{
				return _MinLength;
			}
		}

		public LengthValidator(string errorMsg, string text, PropertyInfo propertyInfo, int minLength, int maxLength) : base(errorMsg, text, propertyInfo)
		{
			if (string.IsNullOrEmpty(errorMsg))
			{
				ErrorMsg = string.Format(DefaultErrorMessages.Length, text, minLength, maxLength);
			}
			_MinLength = minLength;
			_MaxLength = maxLength;
		}

		protected override bool Validation(object value)
		{
			bool flag;
			if (value != null)
			{
				string str = value.ToString();
				if (!string.IsNullOrEmpty(str))
				{
					int length = str.Length;
					flag = (length < _MinLength ? false : length <= _MaxLength);
				}
				else
				{
					flag = true;
				}
			}
			else
			{
				flag = true;
			}
			return flag;
		}
	}
}